﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmDoTuoiTrungBinh.
	/// </summary>
	public class frmDoTuoiTrungBinh : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        Language lan = new Language();
		private DataSet ds=new DataSet();
        string m_user = "",sql="";    
		private System.Windows.Forms.DataGrid dgrDoTuoiTB;
		private System.Windows.Forms.Panel panDoTuoiNamNu;
		private System.Windows.Forms.GroupBox gpbNNPBDV;
		private System.Windows.Forms.RadioButton rbtNam;
		private System.Windows.Forms.RadioButton rbtNu;
		private System.Windows.Forms.RadioButton rbtDonVi;
		private System.Windows.Forms.RadioButton rbtPhongBan;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label lblTuoiTB;
		private System.Windows.Forms.Label lblTuoiLN;
		private System.Windows.Forms.Label lblTongSoNN;
		private System.Windows.Forms.Label lblTuoiNN;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button butKetThuc;
		private System.Windows.Forms.Button butChon;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDoTuoiTrungBinh()
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmDoTuoiTrungBinh));
            this.dgrDoTuoiTB = new System.Windows.Forms.DataGrid();
            this.panDoTuoiNamNu = new System.Windows.Forms.Panel();
            this.label5 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.lblTuoiTB = new System.Windows.Forms.Label();
            this.lblTuoiLN = new System.Windows.Forms.Label();
            this.lblTongSoNN = new System.Windows.Forms.Label();
            this.lblTuoiNN = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.gpbNNPBDV = new System.Windows.Forms.GroupBox();
            this.rbtDonVi = new System.Windows.Forms.RadioButton();
            this.rbtPhongBan = new System.Windows.Forms.RadioButton();
            this.rbtNu = new System.Windows.Forms.RadioButton();
            this.rbtNam = new System.Windows.Forms.RadioButton();
            this.butKetThuc = new System.Windows.Forms.Button();
            this.butChon = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDoTuoiTB)).BeginInit();
            this.panDoTuoiNamNu.SuspendLayout();
            this.gpbNNPBDV.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDoTuoiTB
            // 
            this.dgrDoTuoiTB.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDoTuoiTB.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDoTuoiTB.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDoTuoiTB.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDoTuoiTB.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDoTuoiTB.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDoTuoiTB.CaptionText = "Danh sách nhân viên";
            this.dgrDoTuoiTB.CaptionVisible = false;
            this.dgrDoTuoiTB.DataMember = "";
            this.dgrDoTuoiTB.FlatMode = true;
            this.dgrDoTuoiTB.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDoTuoiTB.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDoTuoiTB.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDoTuoiTB.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDoTuoiTB.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDoTuoiTB.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDoTuoiTB.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDoTuoiTB.LinkColor = System.Drawing.Color.Teal;
            this.dgrDoTuoiTB.Location = new System.Drawing.Point(8, 8);
            this.dgrDoTuoiTB.Name = "dgrDoTuoiTB";
            this.dgrDoTuoiTB.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDoTuoiTB.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDoTuoiTB.RowHeaderWidth = 10;
            this.dgrDoTuoiTB.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDoTuoiTB.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDoTuoiTB.Size = new System.Drawing.Size(400, 216);
            this.dgrDoTuoiTB.TabIndex = 0;
            // 
            // panDoTuoiNamNu
            // 
            this.panDoTuoiNamNu.Controls.Add(this.label5);
            this.panDoTuoiNamNu.Controls.Add(this.label2);
            this.panDoTuoiNamNu.Controls.Add(this.lblTuoiTB);
            this.panDoTuoiNamNu.Controls.Add(this.lblTuoiLN);
            this.panDoTuoiNamNu.Controls.Add(this.lblTongSoNN);
            this.panDoTuoiNamNu.Controls.Add(this.lblTuoiNN);
            this.panDoTuoiNamNu.Controls.Add(this.label4);
            this.panDoTuoiNamNu.Controls.Add(this.label3);
            this.panDoTuoiNamNu.Controls.Add(this.label1);
            this.panDoTuoiNamNu.Location = new System.Drawing.Point(8, 232);
            this.panDoTuoiNamNu.Name = "panDoTuoiNamNu";
            this.panDoTuoiNamNu.Size = new System.Drawing.Size(400, 65);
            this.panDoTuoiNamNu.TabIndex = 1;
            this.panDoTuoiNamNu.Visible = false;
            // 
            // label5
            // 
            this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label5.ForeColor = System.Drawing.Color.DarkBlue;
            this.label5.Location = new System.Drawing.Point(16, 38);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(80, 24);
            this.label5.TabIndex = 9;
            this.label5.Text = "Tổng số nữ :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label5.Visible = false;
            // 
            // label2
            // 
            this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(192, 8);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(88, 24);
            this.label2.TabIndex = 8;
            this.label2.Text = "Tuổi lớn nhất :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lblTuoiTB
            // 
            this.lblTuoiTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTuoiTB.ForeColor = System.Drawing.Color.Red;
            this.lblTuoiTB.Location = new System.Drawing.Point(285, 30);
            this.lblTuoiTB.Name = "lblTuoiTB";
            this.lblTuoiTB.Size = new System.Drawing.Size(96, 24);
            this.lblTuoiTB.TabIndex = 7;
            this.lblTuoiTB.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // lblTuoiLN
            // 
            this.lblTuoiLN.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTuoiLN.ForeColor = System.Drawing.Color.Red;
            this.lblTuoiLN.Location = new System.Drawing.Point(286, 5);
            this.lblTuoiLN.Name = "lblTuoiLN";
            this.lblTuoiLN.Size = new System.Drawing.Size(96, 24);
            this.lblTuoiLN.TabIndex = 6;
            this.lblTuoiLN.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // lblTongSoNN
            // 
            this.lblTongSoNN.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTongSoNN.ForeColor = System.Drawing.Color.Red;
            this.lblTongSoNN.Location = new System.Drawing.Point(96, 35);
            this.lblTongSoNN.Name = "lblTongSoNN";
            this.lblTongSoNN.Size = new System.Drawing.Size(72, 24);
            this.lblTongSoNN.TabIndex = 5;
            this.lblTongSoNN.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // lblTuoiNN
            // 
            this.lblTuoiNN.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblTuoiNN.ForeColor = System.Drawing.Color.Red;
            this.lblTuoiNN.Location = new System.Drawing.Point(96, 5);
            this.lblTuoiNN.Name = "lblTuoiNN";
            this.lblTuoiNN.Size = new System.Drawing.Size(72, 24);
            this.lblTuoiNN.TabIndex = 4;
            this.lblTuoiNN.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // label4
            // 
            this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label4.ForeColor = System.Drawing.Color.DarkBlue;
            this.label4.Location = new System.Drawing.Point(192, 34);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(90, 24);
            this.label4.TabIndex = 3;
            this.label4.Text = "Độ tuổi trung bình :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label3
            // 
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(8, 32);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(80, 24);
            this.label3.TabIndex = 1;
            this.label3.Text = "Tổng số nam :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label3.Visible = false;
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(8, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(88, 24);
            this.label1.TabIndex = 0;
            this.label1.Text = "Tuổi nhỏ nhất :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // gpbNNPBDV
            // 
            this.gpbNNPBDV.Controls.Add(this.rbtDonVi);
            this.gpbNNPBDV.Controls.Add(this.rbtPhongBan);
            this.gpbNNPBDV.Controls.Add(this.rbtNu);
            this.gpbNNPBDV.Controls.Add(this.rbtNam);
            this.gpbNNPBDV.Location = new System.Drawing.Point(47, 303);
            this.gpbNNPBDV.Name = "gpbNNPBDV";
            this.gpbNNPBDV.Size = new System.Drawing.Size(320, 43);
            this.gpbNNPBDV.TabIndex = 2;
            this.gpbNNPBDV.TabStop = false;
            // 
            // rbtDonVi
            // 
            this.rbtDonVi.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.rbtDonVi.ForeColor = System.Drawing.Color.Blue;
            this.rbtDonVi.Location = new System.Drawing.Point(247, 13);
            this.rbtDonVi.Name = "rbtDonVi";
            this.rbtDonVi.Size = new System.Drawing.Size(63, 20);
            this.rbtDonVi.TabIndex = 2;
            this.rbtDonVi.Text = "Đơn vị";
            this.rbtDonVi.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // rbtPhongBan
            // 
            this.rbtPhongBan.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.rbtPhongBan.ForeColor = System.Drawing.Color.Blue;
            this.rbtPhongBan.Location = new System.Drawing.Point(152, 13);
            this.rbtPhongBan.Name = "rbtPhongBan";
            this.rbtPhongBan.Size = new System.Drawing.Size(91, 20);
            this.rbtPhongBan.TabIndex = 3;
            this.rbtPhongBan.Text = "Phòng ban";
            this.rbtPhongBan.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // rbtNu
            // 
            this.rbtNu.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.rbtNu.ForeColor = System.Drawing.Color.Blue;
            this.rbtNu.Location = new System.Drawing.Point(84, 13);
            this.rbtNu.Name = "rbtNu";
            this.rbtNu.Size = new System.Drawing.Size(43, 20);
            this.rbtNu.TabIndex = 1;
            this.rbtNu.Text = "Nữ";
            this.rbtNu.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // rbtNam
            // 
            this.rbtNam.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.rbtNam.ForeColor = System.Drawing.Color.Blue;
            this.rbtNam.Location = new System.Drawing.Point(20, 13);
            this.rbtNam.Name = "rbtNam";
            this.rbtNam.Size = new System.Drawing.Size(55, 20);
            this.rbtNam.TabIndex = 0;
            this.rbtNam.Text = "Nam";
            this.rbtNam.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // butKetThuc
            // 
            this.butKetThuc.BackColor = System.Drawing.Color.AliceBlue;
            this.butKetThuc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butKetThuc.ForeColor = System.Drawing.Color.DarkBlue;
            this.butKetThuc.Image = global::Human.Properties.Resources.close_r;
            this.butKetThuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butKetThuc.Location = new System.Drawing.Point(203, 351);
            this.butKetThuc.Name = "butKetThuc";
            this.butKetThuc.Size = new System.Drawing.Size(75, 28);
            this.butKetThuc.TabIndex = 1;
            this.butKetThuc.Text = "Kết thúc";
            this.butKetThuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butKetThuc.UseVisualStyleBackColor = true;
            this.butKetThuc.Click += new System.EventHandler(this.butKetThuc_Click);
            // 
            // butChon
            // 
            this.butChon.BackColor = System.Drawing.Color.AliceBlue;
            this.butChon.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butChon.ForeColor = System.Drawing.Color.DarkBlue;
            this.butChon.Image = global::Human.Properties.Resources.t_search;
            this.butChon.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butChon.Location = new System.Drawing.Point(137, 352);
            this.butChon.Name = "butChon";
            this.butChon.Size = new System.Drawing.Size(60, 28);
            this.butChon.TabIndex = 0;
            this.butChon.Text = "Chọn";
            this.butChon.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butChon.UseVisualStyleBackColor = true;
            this.butChon.Click += new System.EventHandler(this.butChon_Click);
            // 
            // frmDoTuoiTrungBinh
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(424, 381);
            this.Controls.Add(this.gpbNNPBDV);
            this.Controls.Add(this.panDoTuoiNamNu);
            this.Controls.Add(this.dgrDoTuoiTB);
            this.Controls.Add(this.butChon);
            this.Controls.Add(this.butKetThuc);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmDoTuoiTrungBinh";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Độ tuổi trung bình";
            this.Load += new System.EventHandler(this.frmDoTuoiTrungBinh_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDoTuoiTB)).EndInit();
            this.panDoTuoiNamNu.ResumeLayout(false);
            this.gpbNNPBDV.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		private void butKetThuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void butChon_Click(object sender, System.EventArgs e)
		{
			try
			{
				lblTongSoNN.Text="";			
				if (rbtNam.Checked==true)
				{	
					try
					{
						panDoTuoiNamNu.Visible=true;
						TongsoNam();
						label3.Visible=true;
						label5.Visible=false;
						ds=f_DoTuoiTB_nam();
						dgrDoTuoiTB.DataSource=null;
						Loadgrid();
						Tuoinam();
					}
					catch
					{
						MessageBox.Show(lan.Change_language_MessageText("Không có dữ liệu"),AccessData.Msg);
					}
				}
				if (rbtNu.Checked==true)
				{
					try
					{
						panDoTuoiNamNu.Visible=true;
						TongsoNu();
						label3.Visible=false;
						label5.Visible=true;
						ds=f_DoTuoiTB_nu();
						dgrDoTuoiTB.DataSource=null;
						Loadgrid();
						Tuoinu();
					}
					catch//(Exception ex)
					{
						MessageBox.Show(lan.Change_language_MessageText("Không có dữ liệu"),AccessData.Msg);
					}
				}
				if (rbtPhongBan.Checked==true)
				{
					try
					{
						panDoTuoiNamNu.Visible=false;
						label3.Visible=false;
						label5.Visible=false;
						dgrDoTuoiTB.DataSource=null;
						LoadgridBoPhan();					
					}
					catch//(Exception ex)
					{
						MessageBox.Show(lan.Change_language_MessageText("Không có dữ liệu"),AccessData.Msg);
					}
				}
				if(rbtDonVi.Checked==true)
				{
					try
					{
						panDoTuoiNamNu.Visible=false;
						label3.Visible=false;
						label5.Visible=false;
						dgrDoTuoiTB.DataSource=null;
						LoadgridDonVi();					
					}
					catch//(Exception ex)
					{
						MessageBox.Show(lan.Change_language_MessageText("Không có dữ liệu"),AccessData.Msg);
					}
				}
			}
			catch{}
		}	
	    private void Loadgrid()
			{
				
				dgrDoTuoiTB.TableStyles.Clear();
				DataGridTableStyle ts = new DataGridTableStyle();
				ts.MappingName = ds.Tables[0].TableName;
					
			    ts.AlternatingBackColor = Color.Beige;
				ts.BackColor = Color.GhostWhite;
				ts.ForeColor = Color.MidnightBlue;
				ts.GridLineColor = Color.RoyalBlue;
				ts.HeaderBackColor = Color.MidnightBlue;
				ts.HeaderForeColor = Color.Lavender;
				ts.SelectionBackColor = Color.Teal;
				ts.SelectionForeColor = Color.PaleGreen;
				
				DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
				TextCol1.MappingName = "mnvmay";
				TextCol1.HeaderText = lan.Change_language_MessageText("Mã Nhân Viên");
				TextCol1.Width = 90;
				TextCol1.Alignment=HorizontalAlignment.Left;
				ts.GridColumnStyles.Add(TextCol1);
				dgrDoTuoiTB.TableStyles.Add(ts);
			
				DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
				TextCol2.MappingName = "ho";
				TextCol2.HeaderText = lan.Change_language_MessageText("Họ Nhân Viên");
				TextCol2.Width = 120;
				TextCol2.Alignment=HorizontalAlignment.Left;
				ts.GridColumnStyles.Add(TextCol2);
				dgrDoTuoiTB.TableStyles.Add(ts);
			
				DataGridTextBoxColumn TextCol3=new DataGridTextBoxColumn();
				TextCol3.MappingName = "ten";
				TextCol3.HeaderText = lan.Change_language_MessageText("Tên Nhân Viên");
				TextCol3.Width = 80;
				TextCol3.Alignment=HorizontalAlignment.Left;
				ts.GridColumnStyles.Add(TextCol3);
				dgrDoTuoiTB.TableStyles.Add(ts);
			
				DataGridTextBoxColumn TextCol4=new DataGridTextBoxColumn();
				TextCol4.MappingName = "phai";
				TextCol4.HeaderText = lan.Change_language_MessageText("Phái");
				TextCol4.Width = 60;
				TextCol4.Alignment=HorizontalAlignment.Left;
				ts.GridColumnStyles.Add(TextCol4);
				dgrDoTuoiTB.TableStyles.Add(ts);
			
			    DataGridTextBoxColumn TextCol5=new DataGridTextBoxColumn();
			    TextCol5.MappingName = "namsinh";
			    TextCol5.HeaderText = lan.Change_language_MessageText("Năm Sinh");
			    TextCol5.Width = 60;
			    TextCol5.Alignment=HorizontalAlignment.Left;
			    ts.GridColumnStyles.Add(TextCol5);
			    dgrDoTuoiTB.TableStyles.Add(ts);
			    ts.DataGrid.DataSource=ds.Tables[0];
                CurrencyManager cm = (CurrencyManager)BindingContext[dgrDoTuoiTB.DataSource, dgrDoTuoiTB.DataMember];
                DataView dv = (DataView)cm.List;
                dv.AllowDelete = false;
                dv.AllowEdit = false;
                dv.AllowNew = false;
			}
		private void LoadgridDonVi()
		{
			ds=f_DonviTS();
			dgrDoTuoiTB.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds.Tables[0].TableName;
					
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
				
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "tongso";
			TextCol1.HeaderText = lan.Change_language_MessageText("Tổng số NV");
			TextCol1.Width = 80;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDoTuoiTB.TableStyles.Add(ts);
			
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "tongnam";
			TextCol2.HeaderText = lan.Change_language_MessageText("Tổng Nam");
			TextCol2.Width = 80;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDoTuoiTB.TableStyles.Add(ts);
			
			DataGridTextBoxColumn TextCol3=new DataGridTextBoxColumn();
			TextCol3.MappingName = "tongnu";
			TextCol3.HeaderText = lan.Change_language_MessageText("Tổng Nữ");
			TextCol3.Width = 80;
			TextCol3.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol3);
			dgrDoTuoiTB.TableStyles.Add(ts);
			
			DataGridTextBoxColumn TextCol4=new DataGridTextBoxColumn();
			TextCol4.MappingName = "tuoiTB";
			TextCol4.HeaderText = lan.Change_language_MessageText("Độ Tuổi Trung Bình");
			TextCol4.Width = 120;			
			TextCol4.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol4);
			dgrDoTuoiTB.TableStyles.Add(ts);
			
			ts.DataGrid.DataSource=ds.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDoTuoiTB.DataSource, dgrDoTuoiTB.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowDelete = false;
            dv.AllowEdit = false;
            dv.AllowNew = false;
		}
		private void LoadgridBoPhan()
		{
            ds = f_phongban();
			dgrDoTuoiTB.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds.Tables[0].TableName;
					
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
				
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "tenbp";
			TextCol1.HeaderText = lan.Change_language_MessageText("Tên Phòng Ban");
			TextCol1.Width = 150;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDoTuoiTB.TableStyles.Add(ts);
			
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "tongPban";
			TextCol2.HeaderText = lan.Change_language_MessageText("Tổng");
			TextCol2.Width = 80;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDoTuoiTB.TableStyles.Add(ts);
			
			DataGridTextBoxColumn TextCol3=new DataGridTextBoxColumn();
			TextCol3.MappingName = "tuoiTB";
			TextCol3.HeaderText = lan.Change_language_MessageText("Độ Tuổi Trung Bình");
			TextCol3.Width = 120;
			TextCol3.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol3);
			dgrDoTuoiTB.TableStyles.Add(ts);			
			
			ts.DataGrid.DataSource=ds.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDoTuoiTB.DataSource, dgrDoTuoiTB.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowDelete = false;
            dv.AllowEdit = false;
            dv.AllowNew = false;
		}
		private void Tuoinu()
		{
			try
			{
				DataSet dss =new DataSet();
				sql="select max(namsinh) as maxns,min(namsinh) as minns,";
                sql += " round(avg(to_number(to_char(now(),'yyyy'),'9999S') - to_number(namsinh,'9999S')),2) as tb ";
                sql += " from " + m_user + ".llnv a ";
                sql += " inner join "+m_user + ".hopdong b on a.manv=b.manv ";
                sql += " inner join "+m_user+".max_lan ml on b.manv=ml.manv";
				sql += " where b.lan=ml.lan and a.phai<>'Nam' ";
                sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('"+DateTime.Now.Date.ToString("dd/MM/yyyy")+"','dd/mm/yyyy'))";
				dss =mDB.get_data(sql);
				if(dss.Tables[0].Rows.Count >0)
				{
					int i=0;
					lblTuoiNN.Text="";
					lblTuoiLN.Text="";
					lblTuoiTB.Text="";
					i=System.DateTime.Now.Year -int.Parse( dss.Tables[0].Rows[0]["minns"].ToString());
					lblTuoiLN.Text=i.ToString();
					i =System.DateTime.Now.Year -int.Parse(dss.Tables[0].Rows[0]["maxns"].ToString());
					lblTuoiNN.Text=i.ToString();
					decimal j =decimal.Parse(dss.Tables[0].Rows[0]["tb"].ToString());
					lblTuoiTB.Text=j.ToString();
				}
			}
			catch{}

		}
		private void Tuoinam()
		{
			try
			{
				DataSet dss =new DataSet();
				string sql="";
				sql="select max(namsinh) as maxns,min(namsinh) as minns,";
                sql += " round(avg(to_number(to_char(now(),'yyyy'),'9999S')-to_number(namsinh,'9999S')),2) as tb ";
                sql += " from " + m_user + ".llnv a ";
                sql += " inner join " + m_user + ".hopdong b on a.manv=b.manv ";
                sql += " inner join "+m_user+".max_lan ml on b.manv=ml.manv";
				sql += " where b.lan=ml.lan and a.phai='Nam'";
                sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
				dss =mDB.get_data(sql);
				if(dss.Tables[0].Rows.Count >0)
				{
					int i=0;
					lblTuoiNN.Text="";
					lblTuoiLN.Text="";
					lblTuoiTB.Text="";
					i=System.DateTime.Now.Year -int.Parse( dss.Tables[0].Rows[0]["minns"].ToString());
					lblTuoiLN.Text=i.ToString();
					i =System.DateTime.Now.Year -int.Parse(dss.Tables[0].Rows[0]["maxns"].ToString());
					lblTuoiNN.Text=i.ToString();
					decimal j =decimal.Parse(dss.Tables[0].Rows[0]["tb"].ToString());
					lblTuoiTB.Text=j.ToString();		}
			}
			catch{}
		}
	    private void TongsoNam()
		{
			try
			{
                sql = " select count(hd.manv) as tongso";
                sql += " from " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on l.manv=hd.manv";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
                sql+=" where hd.lan = ml.lan and l.phai='Nam'";
                sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
                lblTongSoNN.Text = mDB.get_data(sql).Tables[0].Rows[0]["tongso"].ToString();
			}
			catch{}
	}
		private void TongsoNu()
		{
			try
			{
                sql = "select count(hd.manv) as tongso";
                sql += " from " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on l.manv=hd.manv";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
                sql += " where hd.lan=ml.lan and l.phai='Nữ'";
                sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
                lblTongSoNN.Text=mDB.get_data(sql).Tables[0].Rows[0]["tongso"].ToString();
			}
			catch{}
	}

		private void frmDoTuoiTrungBinh_Load(object sender, System.EventArgs e)
		{
            m_user = mDB.user;
		}
        private DataSet f_DoTuoiTB_nam()
        {
           sql="select mnvmay,ho,ten,phai,namsinh as namsinh_nam " ;
           sql += " from " + m_user + ".llnv l left join " + m_user + ".hopdong hd on l.manv=hd.manv ";
           sql += " inner join " + m_user + ".max_lan ml on hd.manv=ml.manv";
           sql+=" where hd.lan=ml.lan and phai= 'Nam' ";
           sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
           sql += " order by l.manv ";
           return mDB.get_data(sql);
        }
        //f_DoTuoiTB_nu
        private DataSet f_DoTuoiTB_nu()
        {
            sql = "select mnvmay,ho,ten,phai,namsinh as namsinh_nam ";
            sql += " from " + m_user + ".llnv l left join " + m_user + ".hopdong hd on l.manv=hd.manv ";
            sql += " inner join " + m_user + ".max_lan ml on hd.manv=ml.manv";
            sql += " where hd.lan=ml.lan and phai<> 'Nam' ";
            sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
            sql += " order by l.manv";
            return mDB.get_data(sql);
        }
        private DataSet f_phongban()
        {
            sql=" select bp.tenbp," ;
            sql += " Count(bp.madv) AS tongPban," ;
            sql += " round(Sum(to_number(to_char(now(),'yyyy'),'9999S')-to_number(namsinh,'9999S'))/Count(mnvmay)) AS tuoiTB";
            sql += " from " + m_user + ".bophan bp inner join " + m_user + ".llnv l on bp.madv = l.madv ";
            sql += " inner join " + m_user + ".hopdong hd on hd.manv=l.manv ";
            sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv ";
            sql += " where hd.lan=ml.lan ";
            sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
            sql += " group by bp.madv,bp.tenbp,bp.sothutu";
            sql += " order by bp.sothutu";
            return mDB.get_data(sql);            
        }
        private DataSet f_DonviTS()
        {
            sql = "SELECT Count(l.mnvmay) AS tongso,";
            sql += " Sum(case when phai='Nam' then 1 else 0 end) AS tongnam,";
            sql += " Sum(case when phai='Nam' then 0 else 1 end) AS tongnu,";
            sql += " ROUND(Sum(to_number(to_char(now(),'yyyy'),'9999S')-to_number(namsinh,'9999'))/Count(mnvmay)) AS tuoiTB";
            sql += " FROM " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on hd.manv=l.manv ";
            sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
            sql += " where hd.lan=ml.lan";
            sql += " and (ngaynghi is null or to_date(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy') > to_date('" + DateTime.Now.Date.ToString("dd/MM/yyyy") + "','dd/mm/yyyy'))";
            return mDB.get_data(sql); 
        }
	}
}
	

